package com.desire.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

@Component
public class TopicsConfig {

    @Bean
    TopicExchange topicExchange() {
        return new TopicExchange("mqsb-topic");
    }

    @Bean
    Queue purchaseQueue() {
        return new Queue("purchaseQueue");
    }

    @Bean
    Queue systemQueue() {
        return new Queue("systemQueue");
    }


    @Bean
    Binding topciBinding(TopicExchange exchange, @Qualifier("purchaseQueue") Queue queue) {
        return BindingBuilder.bind(queue).to(exchange).with("purchase.*.*");
    }

    @Bean
    Binding topciBinding2(TopicExchange exchange, @Qualifier("systemQueue") Queue queue) {
        return BindingBuilder.bind(queue).to(exchange).with("#.error");
    }


}
